package org.john.javalib;

import java.util.Arrays;
import java.util.List;

/**
 * Created by adsame on 17-2-28.
 */
public class EnumTest {

    public enum NumberEnum {
        UNKNOWN(0),
        ONE(1),
        TWO(2),
        THREE(3);

        private NumberEnum(Integer i) {
            this.value = i;
        }

        public Integer getValue() {
            return value;
        }

        public static NumberEnum getByValue(String s) {
            if (s.equals("1")) {
                return ONE;
            } else if (s.equals("2")) {
                return TWO;

            } else if (s.equals("3")) {
                return THREE;
            }
            return UNKNOWN;
        }

        private int value;
    }

    public enum CaratAdx {
        ADGDT("adgdt"),
        BAIDU("baidu"),
        GOOGLE("google"),
        HUNANTV("hunantv"),
        IQIYI("iqiyi"),
        LETV("letv"),
        MIAOZHEN("miaozhen"),
        SOHU("sohu"),
        TANX("tanx"),
        TXADX("txadx"),
        YOUKU("youku");

        private final String adx;

        private CaratAdx(String adx) {
            this.adx = adx;
        }

        public static CaratAdx getCaratAdxByStr(String adxName) {
            try {
                return CaratAdx.valueOf(adxName);
            } catch (Exception e) {
                System.out.println("Adx name parse error:");
                e.printStackTrace();
                return null;
            }
        }

        public String getValue() {
            return adx;
        }
    }

    public static final List<Integer> RUN_PATH_LIST = Arrays.asList(1, 2);

    public static void main(String[] args) {
//        enumTest1();
        System.out.println(CaratAdx.getCaratAdxByStr("BAIDU"));
        System.out.println("idx:" + RUN_PATH_LIST.get(3));
    }

    public static void enumTest1() {
        NumberEnum e = NumberEnum.getByValue("2");
        switch (e) {
            case UNKNOWN:
                System.out.print("un:" + e);
                break;
            case ONE:
                System.out.print("1:" + e);
                break;
            case TWO:
                System.out.print("2:" + e);
                break;
            case THREE:
                System.out.print("3:" + e);
                break;
        }

    }
}
